/*
    2. Write a program in C to find the length of a string without using library function.

    Test Data :
    Input the string : w3resource.com

    Expected Output :

    Length of the string is : 15 
*/

#include <stdio.h>
#include <stdlib.h>

char* getStr(char *str)
{
    char ch;
    char *p = str;
    while((ch = getchar()) != '\n'){
        *p = ch;
        p++;
    }
    *p = '\0';
    return str;
}

int getStrLen(char *str)
{
    int len = 0;
    char *p = str;
    while(*p != '\0'){
        len++;
        p++;
    }
    len++; // '\0'
    return len;
}

int main(void)
{
    char *str = malloc(1024);
    printf("Input the string : ");
    printf("Length of the string is : %d", getStrLen(getStr(str)));
    return 0;
}